package com.example.xiaohui.rikaoyi;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;

/**
 * Created by XiaoHui on 2016/7/6.
 */
public class TwoActivity extends Activity {
    private  ContentResolver resolver;
    private TextView tv_name;
    private  TextView tv_phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        tv_name= (TextView) findViewById(R.id.tv_name);
        tv_phone= (TextView) findViewById(R.id.tv_phone);
        resolver=getContentResolver();
        selectItem();
    }
    public  void selectItem(){
        Cursor curcor=resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
        while (curcor.moveToNext()){
            //tv_name.setText(curcor.getColumnIndex(curcor.getString(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
           // tv_phone.setText(curcor.getColumnIndex(curcor.getString(1)));
            //String name=curcor.getColumnIndex(String.valueOf(curcor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
            tv_name.setText(curcor.getString(curcor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
            tv_phone.setText(curcor.getString(curcor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHONETIC_NAME)));
        }
    }
}
